package org.bdware.doip.endpoint.doipClient;

import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import org.bdware.doip.core.doipMessage.DoipMessage;
import org.bdware.doip.core.doipMessage.DoipMessageFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ResponseWait {
    Map<Integer, DoipMessageCallback> waitObj = new HashMap<>();

    public void wakeUpAndRemove(int requestID, DoipMessage result) {
        wakeup(requestID,result);
        waitObj.remove(requestID);
    }

    public boolean waitResponse(final int requestID, DoipMessageCallback cb) {
        if (!waitObj.containsKey(requestID)) {
            waitObj.put(requestID, cb);
            return true;
        }
        return false;
    }

    public void wakeup(int requestID, DoipMessage result) {
        DoipMessageCallback ob = waitObj.get(requestID);
        if (ob != null) ob.onResult(result);
    }
}
